package web.init;


import java.sql.Connection;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import bean.Dynamic_information;
import bean.Dynamic_informationList;
import DB.DB_connection_pool;

public class Information_init extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		//ServletContext application = config.getServletContext();
		Timer timer = new Timer();
		timer.schedule(new TimerTask(){public void run(){
			try {
                List<Dynamic_information> dynamic_informations = new ArrayList<Dynamic_information>();
                Dynamic_information dynamic_information;
                
				String select = "select * from dynamic_information";
				Connection conn = DB_connection_pool.data_pool.getConnection();
				PreparedStatement ps_select= conn.prepareStatement(select);
				ResultSet rs = ps_select.executeQuery();
				
				while(rs.next()){
					dynamic_information = new Dynamic_information();
					dynamic_information.setId(rs.getInt("id"));
					dynamic_information.setInformation_id(rs.getString("dynamic_information_id"));
					dynamic_information.setUser_account(rs.getString("user_account"));
					dynamic_information.setDate(rs.getDate("dynamic_information_date"));
					dynamic_information.setPhoto_path(rs.getString("dynamic_photo_path"));
					dynamic_information.setContent(rs.getString("dynamic_information_content"));
					dynamic_information.setAttention_number(rs.getInt("dynamic_information_attention_number"));
					dynamic_information.setForword_number(rs.getInt("dynamic_information_forword_number"));
					dynamic_information.setReview_number(rs.getInt("dynamic_information_review_number"));
					dynamic_information.setPraise_number(rs.getInt("dynamic_information_praise_number"));
					
					dynamic_informations.add(dynamic_information);
				}
				
				Dynamic_informationList.setDynamic_informations(dynamic_informations);
				
				rs.close();
				ps_select.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}}, 0,1000*60*5);
	}
}
